﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ADShop.Models;
using ADShop.Repository;
namespace ADShop.Controllers
{
    public class LoginController : Controller
    {
        //
        // GET: /Login/
        #region "Variable"
          EShopEntities1 adshop = new EShopEntities1(); //ADShopEntities adshop = new ADShopEntities();
        #endregion
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult LoginMember()
        {
            ViewBag.ReturnUrl = Request.Url.AbsolutePath;
            return View();
        }
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult LoginMember(FormCollection fc)
        {
            Session["Member"] = null;
            Member mb = new Member();
            mb.UserEmail = fc["tbEmail"];
            mb.Password = Global.MD5(fc["pwPassword"]);

            Session["Member"] = adshop.Member.Include("InfoMember").Where(e => e.UserEmail == mb.UserEmail && e.Password == mb.Password).FirstOrDefault();
            if (Session["Member"] != null)
            {
                return RedirectToActionPermanent("Index", "Default");
            }
            ViewBag.Error = "E-mail Hoặc Mật Khẩu Không Đúng";
            return View();
        }
    }
}
